import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		token: uni.getStorageSync('token'),
		nickname: uni.getStorageSync('nickname'),
		uid: uni.getStorageSync('uid'),
		sendCodeLastTimstamp:uni.getStorageSync('sendCodeLastTimstamp'),
		isNotShowTiShi:uni.getStorageSync('isNotShowTiShi'),
		groupToken:uni.getStorageSync('groupToken'),
		photo:uni.getStorageSync('photo'), 
		store: '',
		count: 0
	},
	getters: {
		sendCodeLastTimstamp:state=>{
			return state.sendCodeLastTimstamp;
		},
		store:state=>{
			return state.store;
		},
		count:state=>{
			return state.count;
		},
		photo:state=>{
			return state.photo
		},
		nickname:state=>{
			return state.nickname;
		},
		token:state=>{
			return state.token;
		},
		isNotShowTishi:state=>{
			return state.isNotShowTiShi;
		},
		groupToken:state=>{
			return state.groupToken;
		}
	},
	mutations: {
		setGroupToken(state,groupToken){
			state.groupToken=groupToken;
			uni.setStorageSync("groupToken", groupToken);
		},
		setStore(state, store) {
			state.store=store;
		},
		setCount(state, count) {
			state.count = count
		},
		clearGroupToken(state){
			state.groupToken=""
			uni.removeStorageSync("groupToken");
		},
		setIsNotShowTiShi(state,isNotShowTiShi){
			state.isNotShowTiShi=isNotShowTiShi;
			uni.setStorageSync("isNotShowTiShi", isNotShowTiShi);
		},
		setPhoto(state,photo){
			state.photo=photo;
			uni.setStorageSync("photo", photo);
		},
		clearPhoto(state){
			state.photo=""
			uni.removeStorageSync("photo");
		},
		setNickname(state,nickname){
			state.nickname=nickname;
			uni.setStorageSync("nickname", nickname);
		},
		setUid(state,uid){
			state.uid=uid;
			uni.setStorageSync("uid", uid);
		},
		setToken(state,token){
			state.token=token;
			uni.setStorageSync("token", token);
		},
		setSendCodeLastTimstamp(state,sendCodeLastTimstamp){
			state.sendCodeLastTimstamp=sendCodeLastTimstamp;
			uni.setStorageSync("sendCodeLastTimstamp", sendCodeLastTimstamp);
		},
		login(state,info){
			state.token=info.token;
			uni.setStorageSync("token", info.token);
		},
		logout(state){
			state.nickname="";
			state.photo="";
			state.token="";
			state.isNotShowTiShi="";
			uni.removeStorageSync("nickname");
			uni.removeStorageSync("photo");
			uni.removeStorageSync("token");
			uni.removeStorageSync("sendCodeLastTimstamp");
		}
	},
})

export default store